<?php
	session_start();
	$forwardPage = "login.php";
	if(!isset($_SESSION['nit'])){
		header("Location: " . $forwardPage);
		exit();
	}
	$cedula = $_GET["cedula"];
	/** Include PHPExcel */
	require_once 'Excel/Classes/PHPExcel.php';
	
	if (!isset($_SESSION['nit_aliado'])){
		$inputFileName = "Excel/BD_EmpleadosIPS.xls";  
		$inputFileType = PHPExcel_IOFactory::identify($inputFileName);  
		$objReader = PHPExcel_IOFactory::createReader($inputFileType);  
		$objReader -> setReadDataOnly(true);  
		/**  Load $inputFileName to a PHPExcel Object  **/  
		$objPHPExcel = $objReader -> load($inputFileName);  
		$total_sheets = $objPHPExcel -> getSheetCount();
		//echo $total_sheets;
		$allSheetName=$objPHPExcel->getSheetNames();
		$objWorksheet = $objPHPExcel->setActiveSheetIndexByName("Vinculados");
		if ($objWorksheet == NULL)
		{
			$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
		}
		$highestRow = $objWorksheet->getHighestRow(); 
		$highestColumn = $objWorksheet -> getHighestColumn();
		$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
		$result = "{";
		$encontrado = 0;
		for ($row = 10; $row <= $highestRow && $objWorksheet->cellExistsByColumnAndRow(3, $row); ++$row) {
			if ($objWorksheet->getCellByColumnAndRow(3, $row)->getValue() == $cedula){
				$encontrado = $row;
				break;
			}
		}
		if ($encontrado){
			$tipoCargo = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(1, $encontrado)->getValue())));
			$result .= '"tipoCargo": "' . $tipoCargo . '", ';
			$result .= '"nombre": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(2, $encontrado)->getValue()))) . '", ';
			$result .= '"cargo": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(4, $encontrado)->getValue()))) . '", ';
			$result .= '"servicio": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(5, $encontrado)->getValue()))) . '", ';
			$result .= '"coordinador": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(6, $encontrado)->getValue()))) . '", ';
			$result .= '"sexo": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(7, $encontrado)->getValue()))) . '", ';
			$result .= '"hrDia": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(11, $encontrado)->getValue() / 30))) . '", ';
			
			$sedesLimInf = 12;
			$sedesLimSup = 16;
			$filaTitulos = 10;
			for ($col = $sedesLimInf; $col <= $sedesLimSup; ++$col) {
				if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'X'){
					$sede = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow($col, $filaTitulos)->getValue())));
					break;
				}
				else if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'CUCUTA'){
					$sede = "Cucuta";
					break;
				}
				else if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'SIU'){
					$sede = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow($col, $filaTitulos)->getValue())));
					break;
				}
				else if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'UDEA'){
					$sede = 'Universidad';
					break;
				}
				else if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == ''){
					$sede = "";
				}
			}
			if ($sede == 'Leon Xiii') $sede = 'Leon XIII';
			if ($sede == 'B/Quilla' || $sede == 'B/quilla') $sede = 'Barranquilla';
			$result .= '"sedes": "' . $sede . '", ';
			
			$dateCell = $objWorksheet->getCellByColumnAndRow(17, $encontrado);
			$cellValue = $dateCell -> getValue();
			if (preg_match("@[0-9]{" . strlen($cellValue) . "}@", $dateCell -> getValue()) == 1){
				$date = gmdate("Y/n/j", PHPExcel_Shared_Date::ExcelToPHP($cellValue));
			}
			else{
				$stringDate = ucwords(strtolower(trim($dateCell->getValue())));
				//echo $stringDate;
				$caStringArray = str_split($stringDate);
				$aux = "";
				$text = true;
				$num = true;
				$arrayDate = array();
				//echo strlen($stringDate);
				for ($i = 0; $i < strlen($stringDate); $i++){
					if ($text == true){
						if (preg_match("@[\D]+@", $caStringArray[$i]) == 1 && $text == true){
							$aux .= $caStringArray[$i];
						}
						else if (preg_match("@[^\D]+@", $caStringArray[$i]) == 1 && $text == true){
							$text = false;
							array_push($arrayDate, trim($aux));
							$aux = "";
						}
					}
					if ($text == false){
						if (preg_match("@[\d]+@", $caStringArray[$i]) == 1){
							$aux .= $caStringArray[$i];
						}
						else if (preg_match("@[^\d]+@", $caStringArray[$i]) == 1){
							if ($aux != ""){
								array_push($arrayDate, trim($aux));
								$aux = "";
							}
						}
					}
					//echo "AUX: ".$aux."<br />";
					if ($i == strlen($stringDate) - 1 && $aux != ""){
						array_push($arrayDate, $aux);
					}
				}
				$months = array("Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic");
				for ($i = 0; $i < count($months); $i++){
					$arrayAux = str_split($arrayDate[0], 3);
					if ($arrayAux[0] == $months[$i]){
						$arrayDate[0] = $i + 1;
						break;
					}
				}
				$arrayDate[1] = intval($arrayDate[1]);
				if (strlen($arrayDate[2]) == 2){
					$arrayDate[2] = "19" . $arrayDate[2];
				}
				$date = $arrayDate[2] . "/" . $arrayDate[0] . "/" . $arrayDate[1];
			}
			/* 39175790		Agosto 30 de 1983
				72258946		20/11/1980
				1129579050		Abril 02/1987
				25056251		Abril 1/1958
				71607449		Abril 15 / 1961
				76327354		Abril 4/77
				1020430217		Abril 7/ 1990
				71607969		Septiembre30/1961
				41738931		Octubre 30-1958
				79592031		Novirmbre 16 /1972
				39191009		Junio7/1981 */
			/* if (PHPExcel_Shared_Date::isDateTime($dateCell)){
				$date = date("Y/n/j", PHPExcel_Shared_Date::ExcelToPHP($dateCell -> getCalculatedValue()));
			}
			else{
				$stringDate = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(17, $encontrado)->getValue())));
			} */
			//echo date("Y/n/j");
			//echo "VAL " . $dateCell -> getValue() . " CALC " . $dateCell -> getCalculatedValue();
			/* if (preg_match("@[0-9]{1,2}/[0-9]{1,2}/([0-9]{2}|[0-9]{4})@", PHPExcel_Shared_Date::ExcelToPHP($dateCell -> getValue()))){
				$date = date("Y/n/j", PHPExcel_Shared_Date::ExcelToPHP($dateCell -> getValue()));
				echo "DATE";
			} */
				// if (!date_parse(PHPExcel_Shared_Date::ExcelToPHP($dateCell -> getValue()))){
					// $months = array("Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic");
					// echo "ADENTRO";
					// $stringDate = ucwords(strtolower(trim($dateCell->getValue())));
					// echo $stringDate;
					// $arrayDate = preg_split("(\s+|\s*/\s*|-)", $stringDate);
					// if (count($arrayDate) == 3){
						
					// }
					// print_r($arrayDate);
					// echo "AFUERA";
				// }
				// else
				// {
					// $date = date("Y/n/j", PHPExcel_Shared_Date::ExcelToPHP($dateCell -> getValue()));
					// echo "DATE ";
				// }
			// echo $date;
			
			$result .= '"fechaNacimiento": "' . $date . '", ';
			
			if ($tipoCargo == "Asistencial"){
				$result .= '"unidEYA": "Estrategica"';
			}
			else if ($tipoCargo == "Administrativo"){
				$result .= '"unidEYA": "Apoyo"';
			}
			
			
			/* for ($col = 1; $col < $highestColumnIndex; ++$col) {
				/* if (PHPExcel_Shared_Date::isDateTime($objWorksheet->getCellByColumnAndRow($col, $encontrado))) {
					array_push($result, date("Y/M/d",PHPExcel_Shared_Date::ExcelToPHP($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getCalculatedValue())));
					continue;
				} *
				echo $col . "   ";
				$value = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue())));
				echo $value . "<br>";
				if ($col == 8 || $col == 17) {
					//echo date_parse_from_format() . "<br>";
					array_push($result, date("Y/n/j", PHPExcel_Shared_Date::ExcelToPHP($value)));
					continue;
				}
				array_push($result, $value);
			} */
		}
		else{
			$objWorksheet = $objPHPExcel->setActiveSheetIndexByName("APRENDICES");
			if ($objWorksheet == NULL)
			{
				$objWorksheet = $objPHPExcel->setActiveSheetIndex(1);
			}
			$highestRow = $objWorksheet->getHighestRow(); 
			$highestColumn = $objWorksheet -> getHighestColumn();
			$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
			for ($row = 1; $row <= $highestRow && $objWorksheet->cellExistsByColumnAndRow(1, $row); ++$row) {
				if ($objWorksheet->getCellByColumnAndRow(1, $row)->getValue() == $cedula){
					$encontrado = $row;
					break;
				}
			}
			if ($encontrado){
				$result .= '"nombre": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(1, $encontrado)->getValue()))) . '", ';
				$servicio = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(3, $encontrado)->getValue())));
				$result .= '"servicio": "' . $servicio . '", ';
				
				$sedesLimInf = 5;
				$sedesLimSup = 8;
				$filaTitulos = 10;
				for ($col = $sedesLimInf; $col <= $sedesLimSup; ++$col) {
					if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'X'){
						$sede = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow($col, $filaTitulos)->getValue())));
						break;
					}
					else if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'CUCUTA'){
						$sede = "Cucuta";
						break;
					}
					else if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'SIU'){
						$sede = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow($col, $filaTitulos)->getValue())));
						break;
					}
					else if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'UDEA'){
						$sede = 'Universidad';
						break;
					}
					else if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == ''){
						$sede = "";
					}
				}
				if ($sede == 'Leon Xiii') $sede = 'Leon XIII';
				if ($sede == 'B/Quilla' || $sede == 'B/quilla') $sede = 'Barranquilla';
				$result .= '"sedes": "' . $sede . '", ';
				
				$dateCell = $objWorksheet->getCellByColumnAndRow(12, $encontrado);
				$cellValue = $dateCell -> getValue();
				if (preg_match("@[0-9]{" . strlen($cellValue) . "}@", $dateCell -> getValue()) == 1){
					$date = gmdate("Y/n/j", PHPExcel_Shared_Date::ExcelToPHP($cellValue));
				}
				else{
					$stringDate = ucwords(strtolower(trim($dateCell->getValue())));
					//echo $stringDate;
					$caStringArray = str_split($stringDate);
					$aux = "";
					$text = true;
					$num = true;
					$arrayDate = array();
					//echo strlen($stringDate);
					for ($i = 0; $i < strlen($stringDate); $i++){
						if ($text == true){
							if (preg_match("@[\D]+@", $caStringArray[$i]) == 1 && $text == true){
								$aux .= $caStringArray[$i];
							}
							else if (preg_match("@[^\D]+@", $caStringArray[$i]) == 1 && $text == true){
								$text = false;
								array_push($arrayDate, trim($aux));
								$aux = "";
							}
						}
						if ($text == false){
							if (preg_match("@[\d]+@", $caStringArray[$i]) == 1){
								$aux .= $caStringArray[$i];
							}
							else if (preg_match("@[^\d]+@", $caStringArray[$i]) == 1){
								if ($aux != ""){
									array_push($arrayDate, trim($aux));
									$aux = "";
								}
							}
						}
						//echo "AUX: ".$aux."<br />";
						if ($i == strlen($stringDate) - 1 && $aux != ""){
							array_push($arrayDate, $aux);
						}
					}
					$months = array("Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic");
					for ($i = 0; $i < count($months); $i++){
						$arrayAux = str_split($arrayDate[0], 3);
						if ($arrayAux[0] == $months[$i]){
							$arrayDate[0] = $i + 1;
							break;
						}
					}
					$arrayDate[1] = intval($arrayDate[1]);
					if (strlen($arrayDate[2]) == 2){
						$arrayDate[2] = "19" . $arrayDate[2];
					}
					$date = $arrayDate[2] . "/" . $arrayDate[0] . "/" . $arrayDate[1];
				}
				
				$result .= '"fechaNacimiento": "' . $date . '", ';
				$tipoCargo = "Apoyo";
				$result .= '"tipoCargo": "' . $tipoCargo . '", ';
				if ($tipoCargo == "Asistencial"){
					$result .= '"unidEYA": "Estrategica", ';
				}
				else if ($tipoCargo == "Administrativo"){
					$result .= '"unidEYA": "Apoyo", ';
				}
				$result .= '"cargo": "Aprendiz", ';
				$result .= '"coordinador": "' . $servicio . '", ';
				$result .= '"sexo": "M", ';
				$result .= '"hrDia": "8", ';
				$result .= '"unidEYA": "Apoyo"';
			}
		}
	}
	else{
		class MyReadFilter implements PHPExcel_Reader_IReadFilter {
			private $_columns = array();
			public function __construct($column1, $column2) {
				$col1aux = PHPExcel_Cell::columnIndexFromString($column1) - 1;
				$col2aux = PHPExcel_Cell::columnIndexFromString($column2) - 1;
				for ($i = $col1aux; $i <= $col2aux; $i++){
					array_push($this->_columns, PHPExcel_Cell::stringFromColumnIndex($i));
				}
			}

			public function readCell($column, $row, $worksheetName = '') {
				if (in_array($column,$this->_columns)) {
					return true;
				}
				return false;
			}
		}
		$filterSubset = new MyReadFilter("B","AK");
		
		$inputFileName = "Excel/BD_EmpleadosAliados.xls";  
		$inputFileType = PHPExcel_IOFactory::identify($inputFileName);  
		$objReader = PHPExcel_IOFactory::createReader($inputFileType);  
		//$objReader->setLoadSheetsOnly(array("MEDELLIN", "SAN ANDRES"));
		$objReader -> setReadDataOnly(true);
		$objReader->setReadFilter($filterSubset);
		/**  Load $inputFileName to a PHPExcel Object  **/  
		$objPHPExcel = $objReader -> load($inputFileName);  
		$total_sheets = $objPHPExcel -> getSheetCount();
		//echo $total_sheets;
		$objWorksheet = $objPHPExcel->setActiveSheetIndexByName("MEDELLIN");
		if ($objWorksheet == NULL)
		{
			$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
		}
		$highestRow = $objWorksheet->getHighestRow();
		$highestColumn = $objWorksheet -> getHighestColumn();
		$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
		$result = "{";
		$encontrado = 0;
		for ($row = 2; $row <= $highestRow && $objWorksheet->cellExistsByColumnAndRow(1, $row); ++$row) {
			if ($objWorksheet->getCellByColumnAndRow(1, $row)->getValue() == $cedula){
				$encontrado = $row;
				break;
			}
		}
		if ($encontrado){
			$result .= '"nombre": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(2, $encontrado)->getValue()))) . '", ';
			$result .= '"fechaNacimiento": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(3, $encontrado)->getValue()))) . '", ';
			$result .= '"cargo": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(4, $encontrado)->getValue()))) . '", ';
			$tipoCargo = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(5, $encontrado)->getValue())));
			$result .= '"tipoCargo": "' . $tipoCargo . '", ';
			
			$sedesLimInf = 6;
			$sedesLimSup = 13;
			$filaTitulos = 1;
			for ($col = $sedesLimInf; $col <= $sedesLimSup; ++$col) {
				if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'X'){
					$sede = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow($col, $filaTitulos)->getValue())));
					break;
				}
				else if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'N/A'){
					$sede = "";
				}
			}
			if ($sede == 'Leon Xiii') $sede = 'Leon XIII';
			if ($sede == 'San Andres Y Providencia') $sede = 'San Andres';
			$result .= '"sedes": "' . $sede . '", ';
			
			$result .= '"servicio": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(14, $encontrado)->getValue()))) . '", ';
			$result .= '"sexo": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(15, $encontrado)->getValue()))) . '", ';
			
			
			/* $dateCell = $objWorksheet->getCellByColumnAndRow(12, $encontrado);
			$cellValue = $dateCell -> getValue();
			if (preg_match("@[0-9]{" . strlen($cellValue) . "}@", $dateCell -> getValue()) == 1){
				$date = gmdate("Y/n/j", PHPExcel_Shared_Date::ExcelToPHP($cellValue));
			}
			else{
				$stringDate = ucwords(strtolower(trim($dateCell->getValue())));
				//echo $stringDate;
				$caStringArray = str_split($stringDate);
				$aux = "";
				$text = true;
				$num = true;
				$arrayDate = array();
				//echo strlen($stringDate);
				for ($i = 0; $i < strlen($stringDate); $i++){
					if ($text == true){
						if (preg_match("@[\D]+@", $caStringArray[$i]) == 1 && $text == true){
							$aux .= $caStringArray[$i];
						}
						else if (preg_match("@[^\D]+@", $caStringArray[$i]) == 1 && $text == true){
							$text = false;
							array_push($arrayDate, trim($aux));
							$aux = "";
						}
					}
					if ($text == false){
						if (preg_match("@[\d]+@", $caStringArray[$i]) == 1){
							$aux .= $caStringArray[$i];
						}
						else if (preg_match("@[^\d]+@", $caStringArray[$i]) == 1){
							if ($aux != ""){
								array_push($arrayDate, trim($aux));
								$aux = "";
							}
						}
					}
					//echo "AUX: ".$aux."<br />";
					if ($i == strlen($stringDate) - 1 && $aux != ""){
						array_push($arrayDate, $aux);
					}
				}
				$months = array("Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic");
				for ($i = 0; $i < count($months); $i++){
					$arrayAux = str_split($arrayDate[0], 3);
					if ($arrayAux[0] == $months[$i]){
						$arrayDate[0] = $i + 1;
						break;
					}
				}
				$arrayDate[1] = intval($arrayDate[1]);
				if (strlen($arrayDate[2]) == 2){
					$arrayDate[2] = "19" . $arrayDate[2];
				}
				$date = $arrayDate[2] . "/" . $arrayDate[0] . "/" . $arrayDate[1];
			} */
			
			$result .= '"coordinador": "", ';
			$result .= '"hrDia": "", ';
			if ($tipoCargo == "Asistencial"){
				$result .= '"unidEYA": "Estrategica"';
			}
			else if ($tipoCargo == "Administrativo"){
				$result .= '"unidEYA": "Apoyo"';
			}
		}
		else{
			$objWorksheet = $objPHPExcel->setActiveSheetIndexByName("SAN ANDRES");
			if ($objWorksheet == NULL)
			{
				$objWorksheet = $objPHPExcel->setActiveSheetIndex(1);
			}
			$highestRow = $objWorksheet->getHighestRow(); 
			$highestColumn = $objWorksheet -> getHighestColumn();
			$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
			for ($row = 2; $row <= $highestRow && $objWorksheet->cellExistsByColumnAndRow(2, $row); ++$row) {
				if ($objWorksheet->getCellByColumnAndRow(2, $row)->getValue() == $cedula){
					$encontrado = $row;
					break;
				}
			}
			if ($encontrado){
				$result .= '"nombre": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(3, $encontrado)->getValue()))) . '", ';
				$result .= '"cargo": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(4, $encontrado)->getValue()))) . '", ';
				$tipoCargo = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(5, $encontrado)->getValue())));
				$result .= '"tipoCargo": "' . $tipoCargo . '", ';
				
				$sedesLimInf = 6;
				$sedesLimSup = 13;
				$filaTitulos = 1;
				for ($col = $sedesLimInf; $col <= $sedesLimSup; ++$col) {
					if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'X'){
						$sede = ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow($col, $filaTitulos)->getValue())));
						break;
					}
					else if (strtoupper($objWorksheet->getCellByColumnAndRow($col, $encontrado)->getValue()) == 'N/A'){
						$sede = "";
					}
				}
				if ($sede == 'Leon Xiii') $sede = 'Leon XIII';
				if ($sede == 'San Andres Y Providencia') $sede = 'San Andres';
				$result .= '"sedes": "' . $sede . '", ';
				
				$result .= '"servicio": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(14, $encontrado)->getValue()))) . '", ';
				$result .= '"sexo": "' . ucwords(strtolower(trim($objWorksheet->getCellByColumnAndRow(36, $encontrado)->getValue()))) . '", ';
				
				
				/* $dateCell = $objWorksheet->getCellByColumnAndRow(12, $encontrado);
				$cellValue = $dateCell -> getValue();
				if (preg_match("@[0-9]{" . strlen($cellValue) . "}@", $dateCell -> getValue()) == 1){
					$date = gmdate("Y/n/j", PHPExcel_Shared_Date::ExcelToPHP($cellValue));
				}
				else{
					$stringDate = ucwords(strtolower(trim($dateCell->getValue())));
					//echo $stringDate;
					$caStringArray = str_split($stringDate);
					$aux = "";
					$text = true;
					$num = true;
					$arrayDate = array();
					//echo strlen($stringDate);
					for ($i = 0; $i < strlen($stringDate); $i++){
						if ($text == true){
							if (preg_match("@[\D]+@", $caStringArray[$i]) == 1 && $text == true){
								$aux .= $caStringArray[$i];
							}
							else if (preg_match("@[^\D]+@", $caStringArray[$i]) == 1 && $text == true){
								$text = false;
								array_push($arrayDate, trim($aux));
								$aux = "";
							}
						}
						if ($text == false){
							if (preg_match("@[\d]+@", $caStringArray[$i]) == 1){
								$aux .= $caStringArray[$i];
							}
							else if (preg_match("@[^\d]+@", $caStringArray[$i]) == 1){
								if ($aux != ""){
									array_push($arrayDate, trim($aux));
									$aux = "";
								}
							}
						}
						//echo "AUX: ".$aux."<br />";
						if ($i == strlen($stringDate) - 1 && $aux != ""){
							array_push($arrayDate, $aux);
						}
					}
					$months = array("Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic");
					for ($i = 0; $i < count($months); $i++){
						$arrayAux = str_split($arrayDate[0], 3);
						if ($arrayAux[0] == $months[$i]){
							$arrayDate[0] = $i + 1;
							break;
						}
					}
					$arrayDate[1] = intval($arrayDate[1]);
					if (strlen($arrayDate[2]) == 2){
						$arrayDate[2] = "19" . $arrayDate[2];
					}
					$date = $arrayDate[2] . "/" . $arrayDate[0] . "/" . $arrayDate[1];
				} */
				
				$result .= '"fechaNacimiento": "", ';
				$result .= '"coordinador": "", ';
				$result .= '"hrDia": "", ';
				if ($tipoCargo == "Asistencial"){
					$result .= '"unidEYA": "Estrategica"';
				}
				else if ($tipoCargo == "Administrativo"){
					$result .= '"unidEYA": "Apoyo"';
				}
			}
		}
	}
	if ($encontrado){
		include "config.php";

		$valores = array(':nit_empresa' => $_SESSION['nit'],
							':cedula' => $cedula
			);
		
		$query1 = "SELECT id FROM reporte_ausentismo " . 
				"WHERE nit_empresa = :nit_empresa AND cedula = :cedula AND (fecha_registro BETWEEN DATE(CONCAT(YEAR(NOW()), '-01-01')) AND DATE(CONCAT(YEAR(NOW()), '-12-31')))";
		
		$query2 = "SELECT (MAX(cantidad_incapacidades) + 1) AS cantidad_incapacidades FROM reporte_ausentismo " . 
				"WHERE nit_empresa = :nit_empresa AND cedula = :cedula";
		
		try{
			$dbh = new PDO('mysql:host=' . $host . ';dbname=' . $db, $user, $password, $options);
			$stmt = $dbh -> prepare($query1);
			$stmt -> execute($valores);
			/* echo "\nPDOStatement::errorInfo():\n";
			$arr = $stmt->errorInfo();
			print_r($arr); */
			$numFilas = $stmt -> rowCount();
			if ($numFilas >= 1){
				$result .= ', "clasifAno": "Prevalencia"';
			}
			else{
				$result .= ', "clasifAno": "Incidencia"';
			}
			
			$stmt = $dbh -> prepare($query2);
			$stmt -> execute($valores);
			/* echo "\nPDOStatement::errorInfo():\n";
			$arr = $stmt->errorInfo();
			print_r($arr); */
			$numFilas = $stmt -> rowCount();
			//echo $numFilas;
			$reg = $stmt -> fetch();
			if ($reg['cantidad_incapacidades'] != NULL){
				$result .= ', "cantIncapacidades": "' . $reg['cantidad_incapacidades'] . '"';
			}
			else{
				$result .= ', "cantIncapacidades": "1"';
			}
			
			$dbh = null;
		}
		catch (PDOException $e) {
			print "Error!: " . $e->getMessage() . "<br/>";
			die();
		}
	}
	$result .= "}";
	echo ($result);
?>